﻿using System;
using Gonte.Validation;

namespace Gonte.ObjectModel
{
    /// <summary>
    /// Length attributes for strings
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
    public class LengthFieldAttribute
        : FieldAttribute
    {
        public LengthFieldAttribute(int minLength, int maxLength)
        {
            minLength_ = minLength;
            maxLength_ = maxLength;
        }

        public override FieldValidator CreateValidator()
        {
            return new FieldLengthValidator(minLength_, maxLength_);
        }

        public int MinLength
        {
            get { return minLength_; }
        }

        public int MaxLength
        {
            get { return maxLength_; }
        }

        private readonly int minLength_;
        private readonly int maxLength_;
    }
}
